import 'package:dio/dio.dart';
import 'package:sonora/models/sj_config_data.dart';
import 'package:sonora/models/sj_response_data.dart';
import 'package:sonora/services/sj_api_service.dart';
import 'package:sonora/utils/sj_storage_utils.dart';

class SjApiConfigService {

  SjApiConfigService._internal();

  static final SjApiConfigService _instance = SjApiConfigService._internal();

  factory SjApiConfigService() {
    return _instance;
  }

  Future<SjConfigData> getAppConfig() async {
    String? ver;
    SjConfigData? config = await SjStorageUtils.getAppConfig();
    if (config != null && config.ver != null) {
      ver = config.ver;
    }
    SjResponseData response = await SjApiService().client.getAppConfig( ver ?? '0');
    if (response.data != null && response.data is Map<String, dynamic>) {
      return SjConfigData.fromJson(response.data);
    }
    return SjConfigData();
  }
}